package com.github.io.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author: ruiyanglee
 * @date: 2020-09-07 15:34
 * @description: 基础实体类
 */
@Data
public class BaseEntity implements Serializable {
    // 创建时自动填充时间
    @TableField(fill = FieldFill.INSERT, value = "create_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;


    // 更新实体或者某个字段时自动填充更新时间
    @TableField(fill = FieldFill.INSERT_UPDATE, value = "update_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    // 逻辑删除：在properties中
    @TableLogic(delval = "0", value = "1")
    @TableField("del_flag")
    private Integer delFlag;

    //乐观锁处理并发操作
    @Version
    private Integer version;

}
